import java.util.Stack;

/**
 * Created with Intellij JDEA
 * Description:
 * User:
 * Date:2022-05-13
 * Time:12:56
 */
public class 从尾到头打印链表 {

      public class ListNode {
          int val;
         ListNode next;
          ListNode(int x) { val = x; }
      }
    class Solution {
        public int[] reversePrint(ListNode head) {
            Stack<Integer> stack = new Stack<Integer>();
            ListNode cur = head;
            while (cur != null) {
                stack.push(cur.val);
                cur = cur.next;
            }
            int size = stack.size();
            int[] ret = new int[size];
            for (int i = 0; i < size; i++) {
                ret[i] = stack.pop();
            }
            return ret;
        }
    }
}
